<template>
  <div class="score-container">
    <div class="matchs-detail">
      <div class="match-item" :key="i" v-for="(match, i) in matchList">
        <div class="match-content">
          <div class="match-score">
            {{match.home_team_name}}（主）
            <span>VS</span>
            {{match.guest_team_name}}（客）
          </div>
          <div class="match-select" @click="selectMatch(match)">点击展开比分投注区</div>
        </div>
        <div class="match-info">
          <x-icon type="ios-minus-outline" size="20" @click="delMatch(i)"></x-icon>
        </div>
      </div>
    </div>
    <confirm
      v-if="showSelectModal"
      v-model="showSelectModal"
      @on-cancel="showSelectModal=false"
      @on-confirm="confirmSelectModal"
      class="zq-s-pay-score-match-modal"
    >
      <div class="title">
        {{selectedMatch.home_team_name}}
        <img
          class="logo"
          src="../../../assets/imgs/live/zhu.png"
          alt
        >
        <span>VS</span>
        {{selectedMatch.guest_team_name}}
        <img
          class="logo"
          src="../../../assets/imgs/live/ke.png"
          alt
        >
      </div>
      <div class="alert">竞猜全场90分钟（含伤停补时）的比分</div>
      <div class="detail">
        <div class="s">
          <div class="left">主胜</div>
          <div class="right">
            <div
              :key="mindex"
              v-for="(mitem, mindex) in (selectedMatch.bf || []).slice(0, 13)"
              :class="{active: copybf[mindex]===mitem[2] ? 'active' : '', item: true}"
              @click="onMatchSelect(mindex, mitem[2])"
            >
              <div class="jq">{{mitem[1]}}</div>
              <div class="score">{{mitem[2]}}</div>
            </div>
          </div>
        </div>
        <div class="p">
          <div class="left">平</div>
          <div class="right">
            <div
              :key="mindex"
              v-for="(mitem, mindex) in (selectedMatch.bf || []).slice(13, 18)"
              :class="{active: copybf[mindex+13]===mitem[2] ? 'active' : '', item: true}"
              @click="onMatchSelect(mindex+13, mitem[2])"
            >
              <div class="jq">{{mitem[1]}}</div>
              <div class="score">{{mitem[2]}}</div>
            </div>
          </div>
        </div>
        <div class="f">
          <div class="left">主负</div>
          <div class="right">
            <div
              :key="mindex"
              v-for="(mitem, mindex) in (selectedMatch.bf || []).slice(18, 31)"
              :class="{active: copybf[mindex+18]===mitem[2] ? 'active' : '', item: true}"
              @click="onMatchSelect(mindex+18, mitem[2])"
            >
              <div class="jq">{{mitem[1]}}</div>
              <div class="score">{{mitem[2]}}</div>
            </div>
          </div>
        </div>
      </div>
    </confirm>
  </div>
</template>
<script>
import { Confirm } from 'vux';
export default {
  components: {
    Confirm
  },
  props: {
    matchList: {
      type: Array
    },
    selectedMatchs: {
      type: Object
    }
  },
  data () {
    return {
      showSelectModal: false,
      copybf: {},
      selectedMatch: {}
    };
  },
  methods: {
    showDetail (item) {
      item.showDetail = !item.showDetail;
      this.$forceUpdate();
    },
    selectMatch (match) {
      const { nm_matches_id, issue_num } = match;
      const selectedbf =
        this.selectedMatchs[nm_matches_id] &&
        this.selectedMatchs[nm_matches_id][issue_num] &&
        this.selectedMatchs[nm_matches_id][issue_num].bf
          ? this.selectedMatchs[nm_matches_id][issue_num].bf
          : {};
      this.copybf = { ...selectedbf };
      this.selectedMatch = match;
      this.showSelectModal = true;
    },
    confirmSelectModal () {
      const data = { ...this.copybf };
      const { nm_matches_id, issue_num } = this.selectedMatch;
      this.$emit('selectBatchMatch', {
        nm_matches_id,
        issue_num,
        type: 'bf',
        data
      });
    },
    onMatchSelect (index, value) {
      if (this.copybf[index]) {
        this.$delete(this.copybf, index);
      } else {
        this.$set(this.copybf, index, value);
      }
    },
    delMatch (index) {
      const { nm_matches_id } = this.matchList[index];
      this.$delete(this.selectedMatchs, nm_matches_id);
      this.matchList.splice(index, 1);
    }
  }
};
</script>
<style lang="less">
.score-container {
  font-size: 0.24rem;
  .matchs-detail {
      background: #fff3f4;
      .match-item {
        display: flex;
        border-bottom: 1px solid #d2d2d2;
        align-items: center;
        .match-info {
          width: 1.2rem;
          padding: 0.2rem;
          color: #202020;
          font-size: 0.24rem;
          text-align: center;
        }
        .match-content {
              width: 100%;
          padding: 0.2rem;
          .match-score {
            text-align: center;
            margin-bottom: 0.1rem;
            span {
              color: #8a8a8a;
              padding-right: 0.1rem;
            }
          }
          .match-select {
            text-align: center;
            background: #fff;
            border: 1px solid #d2d2d2;
            color: #8a8a8a;
            height: 0.54rem;
            line-height: 0.54rem;
            font-size: 0.2rem;
          }
        }
      }
    }
}
.zq-s-pay-score-match-modal {
    .title {
      font-size: 0.3rem;
      img {
        width: 0.28rem;
      }
      span {
        margin: 0 0.4rem;
      }
    }
    .alert {
      text-align: left;
      color: #b9b9b9;
      font-size: 0.18rem;
      margin-top: 0.2rem;
      margin-bottom: 0.1rem;
    }
    .detail {
      display: flex;
      font-size: 0.2rem;
      width: 5.2rem;
      flex-wrap: wrap;
      .s {
        // width: 5.2rem;
        display: flex;
        width: 100%;
        .left {
          width: 0.2rem;
          padding-left: 0.05rem;
          padding-right: 0.05rem;
          display: inline-block;
          background: #c99feb;
          height: 0.9rem;
          color: #fff;
          padding-top: 0.3rem;
        }
        .right {
          display: inline-block;
          width: 100%;
          text-align: left;
          .item {
            display: inline-block;
            text-align: center;
            width: 14%;
            height: 0.5rem;
            padding-top: 0.1rem;
            background: #fbf3f4;
            &.active {
              background: #d44743;
              color: #fff;
            }
            .score {
              font-size: 0.16rem;
            }
            &:last-child {
              width: 28%;
            }
          }
        }
      }
      .p {
        margin-top: 0.2rem;
        margin-bottom: 0.2rem;
        display: flex;
        width: 100%;
        .left {
          width: 0.2rem;
          padding-left: 0.05rem;
          padding-right: 0.05rem;
          display: inline-block;
          background: #d0dffc;
          height: 0.4rem;
          color: #fff;
          padding-top: 0.2rem;
        }
        .right {
          display: inline-block;
          width: 100%;
          text-align: left;
          .item {
            display: inline-block;
            text-align: center;
            width: 14%;
            height: 0.5rem;
            padding-top: 0.1rem;
            background: #fbf3f4;
            // border: 1px solid #d2d2d2;
            &.active {
              background: #d44743;
              color: #fff;
            }
            // .jq {
            //   font-size: 0.2rem;
            // }
            .score {
              font-size: 0.16rem;
            }
            &:last-child {
              width: 42%;
            }
          }
        }
      }
      .f {
        display: flex;
        width: 100%;
        .left {
          width: 0.2rem;
          padding-left: 0.05rem;
          padding-right: 0.05rem;
          display: inline-block;
          background: #7adf89;
          height: 0.9rem;
          color: #fff;
          padding-top: 0.3rem;
        }
        .right {
          display: inline-block;
          width: 100%;
          text-align: left;
          .item {
            display: inline-block;
            text-align: center;
            width: 14%;
            height: 0.5rem;
            padding-top: 0.1rem;
            background: #d5f6da;
            &.active {
              background: #d44743;
              color: #fff;
            }
            .score {
              font-size: 0.16rem;
            }
            &:last-child {
              width: 28%;
            }
          }
        }
      }
    }
  }
</style>
